<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  

  
  <title>6. Docker三剑客 | Hexo</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="一. 简单介绍Docker的三剑客包含Compose ，Machine ，DockerSwarm。DS已经过时了，Machine也不经常用了，主要使用的还是Compose。俗话说学Docker Compose必会。是docker下的一个开源项目，负责对Docker容器集群的快速编排。为了完成多容器相互配合完成项目部署与应用。Docker Compose 有两个比较重要的概念：    服务（serv">
<meta property="og:type" content="article">
<meta property="og:title" content="6. Docker三剑客">
<meta property="og:url" content="http://yoursite.com/2020/02/29/6.Docker%20%E4%B8%89%E5%89%91%E5%AE%A2/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="一. 简单介绍Docker的三剑客包含Compose ，Machine ，DockerSwarm。DS已经过时了，Machine也不经常用了，主要使用的还是Compose。俗话说学Docker Compose必会。是docker下的一个开源项目，负责对Docker容器集群的快速编排。为了完成多容器相互配合完成项目部署与应用。Docker Compose 有两个比较重要的概念：    服务（serv">
<meta property="og:locale" content="en_US">
<meta property="article:published_time" content="2020-02-29T08:45:41.777Z">
<meta property="article:modified_time" content="2020-04-18T14:24:58.369Z">
<meta property="article:author" content="John Doe">
<meta name="twitter:card" content="summary">
  
    <link rel="alternate" href="/myblog/atom.xml" title="Hexo" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.png">
  
  
    <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  
  
<link rel="stylesheet" href="/myblog/css/style.css">

<meta name="generator" content="Hexo 4.2.0"></head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/myblog/" id="logo">Hexo</a>
      </h1>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/myblog/">Home</a>
        
          <a class="main-nav-link" href="/myblog/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-rss-link" class="nav-icon" href="/myblog/atom.xml" title="RSS Feed"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://yoursite.com"></form>
      </div>
    </div>
  </div>
</header>
      <div class="outer">
        <section id="main"><article id="post-6.Docker 三剑客" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/myblog/2020/02/29/6.Docker%20%E4%B8%89%E5%89%91%E5%AE%A2/" class="article-date">
  <time datetime="2020-02-29T08:45:41.777Z" itemprop="datePublished">2020-02-29</time>
</a>
    
  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      6. Docker三剑客
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h4 id="一-简单介绍"><a href="#一-简单介绍" class="headerlink" title="一. 简单介绍"></a>一. 简单介绍</h4><p>Docker的三剑客包含Compose ，Machine ，DockerSwarm。DS已经过时了，Machine也不经常用了，主要<br>使用的还是Compose。俗话说学Docker Compose必会。是docker下的一个开源项目，负责对Docker容器集群<br>的快速编排。为了完成多容器相互配合完成项目部署与应用。<br>Docker Compose 有两个比较重要的概念：  </p>
<ol>
<li>服务（service）：一个应用的容器，实际上是可以包括若干个运行相同镜像的容器实例。  </li>
<li>项目（project）：由一组相互关联的应用容器组成的一个完整的业务单元，在docker-compose.yml文件<br>中定义。  </li>
<li>Compose 默认是按照一个一个项目进行管理的，它通过子命令对项目中的一组容器进行便捷的生命周期管理。  </li>
<li>Compose 项目是由python编写的，实际上调用了Docker 服务提供的API来对容器进行管理的。因此只要<br>所操作的平台支持Docker API ，那么就可以在其上使用Compose 来进行编排管理。<h4 id="二-Compose-的下载与安装"><a href="#二-Compose-的下载与安装" class="headerlink" title="二. Compose 的下载与安装"></a>二. Compose 的下载与安装</h4>在Linux上下载安装Compose 可以直接登陆网址下载相应的版本就行了。<br>从这儿下载 <a><a href="https://github.com/docker/compose/releases" target="_blank" rel="noopener">https://github.com/docker/compose/releases</a></a>下载最新版本的。</li>
</ol>
<h4 id="三-Compose-yml文件"><a href="#三-Compose-yml文件" class="headerlink" title="三. Compose yml文件"></a>三. Compose yml文件</h4><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">version:</span> <span class="string">"3"</span>                     <span class="string">docker_compose的</span> <span class="string">版本号</span></span><br><span class="line"><span class="attr">services:</span> </span><br><span class="line">    <span class="attr">tomcat:</span></span><br><span class="line">        <span class="attr">restart:</span> <span class="string">aloways</span>         <span class="string">是否自动重启</span></span><br><span class="line">        <span class="attr">image:</span> <span class="string">tomcat</span>            <span class="string">docker镜像名称</span></span><br><span class="line">        <span class="attr">container_name:</span> <span class="string">tomcat</span>   <span class="string">docker容器的名称</span></span><br><span class="line">        <span class="attr">ports:</span></span><br><span class="line">            <span class="bullet">-</span> <span class="number">8080</span><span class="string">:8080</span>      <span class="string">宿主机端口号：镜像端口号</span></span><br></pre></td></tr></table></figure>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker compose up -----&gt; 运行docker_compose </span><br><span class="line">docker compose down -----&gt; 删除docker_compose</span><br></pre></td></tr></table></figure>
<p><strong>运行上面的这两个命令的时候，需要在docker-compose.yml 文件的文件夹路径下面才行</strong></p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://yoursite.com/2020/02/29/6.Docker%20%E4%B8%89%E5%89%91%E5%AE%A2/" data-id="ck95pw3oo0000sad17burbp4a" class="article-share-link">Share</a>
      
      
    </footer>
  </div>
  
    
<nav id="article-nav">
  
  
    <a href="/myblog/2020/02/28/5.Docker%20%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E6%8C%81%E4%B9%85%E5%8C%96/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">5. Docker容器数据持久化</div>
    </a>
  
</nav>

  
</article>

</section>
        
          <aside id="sidebar">
  
    

  
    

  
    
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/myblog/archives/2020/02/">February 2020</a></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/myblog/2020/02/29/6.Docker%20%E4%B8%89%E5%89%91%E5%AE%A2/">6. Docker三剑客</a>
          </li>
        
          <li>
            <a href="/myblog/2020/02/28/5.Docker%20%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E6%8C%81%E4%B9%85%E5%8C%96/">5. Docker容器数据持久化</a>
          </li>
        
          <li>
            <a href="/myblog/2020/02/23/4.Docker%20%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">4. Docker的常用命令</a>
          </li>
        
          <li>
            <a href="/myblog/2020/02/10/3.DockerFile%E5%AE%9A%E5%88%B6%E9%95%9C%E5%83%8F/">3. DockerFile定制镜像</a>
          </li>
        
          <li>
            <a href="/myblog/2020/02/05/2.Java%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B%E7%AC%94%E8%AE%B0/">2. Java并发编程笔记</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2020 John Doe<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>
    </div>
    <nav id="mobile-nav">
  
    <a href="/myblog/" class="mobile-nav-link">Home</a>
  
    <a href="/myblog/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  
<link rel="stylesheet" href="/myblog/fancybox/jquery.fancybox.css">

  
<script src="/myblog/fancybox/jquery.fancybox.pack.js"></script>




<script src="/myblog/js/script.js"></script>




  </div>
</body>
</html>